package cheme.ProcessEditor.Table;

import java.beans.PropertyChangeEvent;
import java.util.List;

import org.eclipse.draw2d.Border;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.swt.graphics.Color;

import cheme.ProcessEditor.ChemePresentation;
import cheme.ProcessEditor.Parts.AbstractParentPart;

public abstract class AbstractSetElementPart extends AbstractParentPart
{
	@Override
	protected List getModelChildren()
	{
		return getModel().getModelChildAndAnnotations();
	}
	
	@Override
	protected void handleInitialization(PropertyChangeEvent evt)
	{
		super.handleInitialization(evt);

		Color fg = ChemePresentation.Fields.initialForeground;
		Color bg = ChemePresentation.Fields.initialBackground;
		Border border = ChemePresentation.Fields.initialBorder;
			
		if(((Boolean)evt.getNewValue()).booleanValue() == false)
		{
			fg = ChemePresentation.Fields.defaultForeground;
			bg = ChemePresentation.Fields.defaultBackground;
			border = ChemePresentation.Fields.defaultBorder;
		}
		
		for(Object child : getChildren())
		{
			/*
			 * If the field is blank, leave it to someone else to worry about.
			 */
			//if(!((Field)((EditPart)child).getModel()).getText().isEmpty())
			{
				((AbstractGraphicalEditPart)child).getFigure().setForegroundColor(fg);
				((AbstractGraphicalEditPart)child).getFigure().setBackgroundColor(bg);
				((AbstractGraphicalEditPart)child).getFigure().setBorder(border);
			}
		}
	}
}
